/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ar.com.s21.poo.dao;

import ar.com.s21.poo.model.TipoPago;
import ar.com.s21.poo.model.Usuario;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Other
 */
public class TipoPagoDAO {

    /**
     *
     * @param tipoPago
     * @return
     * @throws SQLException
     */
    public TipoPago obtenerTipoPagoPorDescripcion(String tipoPago) throws SQLException {
        
        PreparedStatement preparedStatement = null;
        String buscarTipoPago = "SELECT * FROM tipopago where tipo_pago=?";
        TipoPago tp = null;
        try {
            preparedStatement = MySQLConnection.getInstance().preparedStatement(buscarTipoPago);

            preparedStatement.setString(1, tipoPago);
                      
            ResultSet result = preparedStatement.executeQuery();
            
            while(result.next()){
                tp = new TipoPago();
                tp.setIdTipoPago(result.getInt("id_tipo_pago"));
            }
                                 
        } catch (SQLException e) {

            System.out.println(e.getMessage());

        } finally {
            if (preparedStatement != null) {
                preparedStatement.close();
            }
        }
        return tp;
    }

    /**
     *
     * @return
     * @throws SQLException
     */
    public List<TipoPago> obtenerListaTipoPago() throws SQLException {
        PreparedStatement preparedStatement = null;
        String buscarTipoPago = "SELECT * FROM tipopago";
        TipoPago tp = null;
        List<TipoPago> listaTipoPagos= null;
        
        try {
            preparedStatement = MySQLConnection.getInstance().preparedStatement(buscarTipoPago);

                            
            ResultSet result = preparedStatement.executeQuery();
            
            while(result.next()){
                listaTipoPagos = new ArrayList<>();
                tp = new TipoPago();
                tp.setIdTipoPago(result.getInt("id_tipo_pago"));
                tp.setTipoPago(result.getString("tipo_pago"));
                listaTipoPagos.add(tp);
            }
                                 
        } catch (SQLException e) {

            System.out.println(e.getMessage());

        } finally {
            if (preparedStatement != null) {
                preparedStatement.close();
            }
        }
        return listaTipoPagos;
    }
    
}
